﻿using FluentValidation;
using Nop.Admin.Models.Stores;
using Nop.Services.Customers;
using Nop.Services.Localization;

namespace Nop.Admin.Validators.Stores
{
    public class StoreValidator : AbstractValidator<StoreModel>
    {
        public StoreValidator(ILocalizationService localizationService, ICustomerService customerService)
        {
            RuleFor(x => x.Name).NotNull().WithMessage(localizationService.GetResource("Admin.Catalog.Stores.Fields.Name.Required"));
            RuleFor(x => x.CustomerEmail)
               .NotEmpty()
               .WithMessage(localizationService.GetResource("Address.Fields.Email.Required"))
               .EmailAddress()
               .WithMessage(localizationService.GetResource("Common.WrongEmail"))
               .Must(e => customerService.GetCustomerByEmail(e) != null)
               .WithMessage(localizationService.GetResource("Admin.Catalog.Stores.Fields.NotFindCustomerByEmail"));

        }
    }
}